package org.emet.dao;

import org.emet.entity.biz.Registration;
import org.emet.jee.core.dao.Page;
import org.emet.jee.core.dao.arch.ArchDataSourceBaseDao;
import org.emet.service.dto.RegistrationCriteria;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository
public class RegistrationDao extends ArchDataSourceBaseDao<Registration, Long> {

	public Page<Registration> search(Page<Registration> page, RegistrationCriteria criteria) {
		Criteria c = getSession().createCriteria(Registration.class);

		NonEmptyValueHashMap<String, Object> propertyNameValues = new NonEmptyValueHashMap<String, Object>();
		propertyNameValues.put("bizNo", criteria.getBizNo());
		propertyNameValues.put("deadName", criteria.getDeadName());
		propertyNameValues.put("dpyName", criteria.getDpyName());
		propertyNameValues.put("carriageDate", criteria.getCarriageDate());
		propertyNameValues.put("vehLpn", criteria.getVehLpn());
		propertyNameValues.put("client", criteria.getClient());
		propertyNameValues.put("cPyName", criteria.getcPyName());
		propertyNameValues.put("phone", criteria.getPhone());

		c.add(Restrictions.allEq(propertyNameValues));
		page.setOrderBy("id");
		page.setOrder("desc");
		return findPage(page, c);
	}
}
